import SwiftUI

struct FoodHomeView: View {
    @State private var selectedFoodType: FoodTypeItemRespModel?
    @State private var searchContent: String = ""
    
    @Environment(Router.self) private var router
    @Environment(PopupModel.self) private var popup
    @Environment(IndicatorModel.self) private var indicator
    @Environment(LocationService.self) private var locationService
    
    var showFoodType: Bool

    var body: some View {
        VStack(spacing: 12.0) {
            VStack(spacing: 8.0) {
                // 地点
                HStack(spacing: 2.0) {
                    Image(.iconMapMarker)
                    Text(locationService.cityName)
                        .font(.alibabaPuHuiTi(size: 16.0, weight: .medium))
                        .foregroundStyle(Color.fs020000)
                    Spacer()
                }
                // 搜索
                SearchView(searchContent: $searchContent) {
                    router.push(AppRoute.searchFoodStoreView(search: searchContent))
                    searchContent = ""
                }
            }
            .padding(.horizontal, 8.0)

            VStack(spacing: 0) {
                // 美食分类
                if showFoodType {
                    FoodTypeView(selectedType: $selectedFoodType)
                        .padding(.top, 24.0)
                }
                
                FoodStoreListView(selectedFoodType: selectedFoodType)
                    .padding(.top, 20.0)
            }
            .background {
                UnevenRoundedRectangle(topLeadingRadius: 20.0, topTrailingRadius: 20.0)
                    .fill(.fsF5F5F5)
            }
            .ignoresSafeArea(.all, edges: .bottom)
        }
        .background(Color.fsFFC600, ignoresSafeAreaEdges: .top)
    }

}

#Preview {
    FoodHomeView(showFoodType: true)
        .environment(Router())
        .environment(PopupModel())
        .environment(IndicatorModel())
}
